package cn.minimelon.cushaw.view.datadef;

import cn.minimelon.bittermelon.bean.AjaxResult;
import cn.minimelon.bittermelon.bean.LoginUser;
import cn.minimelon.bittermelon.solon.BaseController;
import cn.minimelon.bittermelon.utils.Melon;
import cn.minimelon.cushaw.entity.SysArea;
import cn.minimelon.cushaw.service.SysAreaService;
import org.beetl.sql.mapper.annotation.Update;
import org.noear.solon.annotation.*;

import java.util.List;

@Controller
@Mapping("/a/dataDef/area")
public class AreaController extends BaseController {
    @Inject
    SysAreaService areaService;

    @Get
    @Mapping("/{uid}")
    public AjaxResult<SysArea> select(String uid) {
        return null;
    }

    @Get
    @Mapping("/search")
    public AjaxResult<Object> search() {
        List<SysArea> list = areaService.selectAll(null);
        return Melon.success(list);
    }

    @Post
    @Mapping("/save")
    public AjaxResult<Object> save(SysArea area) {
        LoginUser user = this.getLoginUser();
        areaService.save(area, user);
        return Melon.success();
    }

    @Post
    @Mapping("/update")
    public AjaxResult<Object> update(SysArea area) {
        LoginUser user = this.getLoginUser();
        int count = areaService.update(area, user);
        if (count > 0) {
            return Melon.success();
        }
        return Melon.error("UPDATE_FAILURE");
    }

    @Delete
    @Mapping("/{uid}")
    public AjaxResult<Object> delete(String uid) {
        return null;
    }
}
